package com.zuo.demo01.service.impl;


import com.zuo.demo01.dao.CatagoryMapper;
import com.zuo.demo01.pojo.Catagory;
import com.zuo.demo01.service.CatagoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CatagoryServiceImpl implements CatagoryService {

    @Autowired
    private CatagoryMapper catagoryMapper;

    @Override
    public List<Catagory> findAll() {
        return catagoryMapper.findAll();
    }

    @Override
    public List<Catagory> findByPage(Map<String, Integer> map) {
        return catagoryMapper.findByPage(map);
    }

    @Override
    public Catagory findByName(Catagory catagory) {
        Map<String,Object> map = new HashMap<>();
        map.put("name",catagory.getName());
        return catagoryMapper.findByName(map);
    }

    @Override
    public int count() {
        return catagoryMapper.count();
    }

    @Override
    public int insert(Catagory catagory) {
        Date date = new Date(System.currentTimeMillis());
        catagory.setCreateTime(date);
        return catagoryMapper.insert(catagory);
    }

    @Override
    public int delete(int id) {
        return catagoryMapper.delete(id);
    }

    @Override
    public int update(Catagory catagory) {
        return catagoryMapper.update(catagory);
    }


}
